package org.devocean.groupbuying.service.impl;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.devocean.groupbuying.dao.BoxDAO;
import org.devocean.groupbuying.domain.Box;
import org.devocean.groupbuying.service.BoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BoxServiceImpl implements BoxService {

	@Autowired
	private BoxDAO boxDAO;
	
	@Transactional(readOnly=true)
	public List<Box> findBoxesEntries(int firstResult, int maxResults) {
		return boxDAO.findBoxEntries(firstResult, maxResults);
	}

	@Transactional(readOnly=true)
	public List<Box> findAllBoxes() {
		return boxDAO.findAllBoxes();
	}

	@Transactional(readOnly=true)
	public Box findBoxById(Integer id) {
		return boxDAO.findBoxById(id);
	}

	@Transactional
	public Box addOrUpdateBox(Box box) {
		if (box.getBox() != null && box.getBox().getBoxID() == null) 
			box.setBox(null); 
		//box = null;
		if(box.getBoxID() != null)
			return boxDAO.updateBox(box);
		else{
			return boxDAO.saveBoxe(box);
		}
	}

	@Transactional
	public void deleteBox(Integer id) {
		boxDAO.deleteBox(id);

	}

	@Transactional(readOnly=true)
	public long countBoxes() {
		return boxDAO.countBoxes();
	}

	public Map<String, Object> search(String searchText, ConcurrentHashMap<String, Object> searchResult) {
		return searchResult;
		
	}

}
